// 
const path = require('path');
// 加载两个模块
const { app, BrowserWindow, ipcMain } = require('electron');

// 创建窗口 并 加载内容
const createWindow = () => {
  const win1 = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })
  const win2 = new BrowserWindow({
    width: 800,
    height: 600,
  })

  const win3 = new BrowserWindow({
    width: 800,
    height: 600,
  })
  win1.loadFile(path.join(__dirname, 'index.html'));
  win1.on('closed', () => {
    console.log('win1-closed');
  })
  win2.on('closed', () => {
    console.log('win2-closed');
  })
  win3.on('closed', () => {
    console.log('win3-closed');
  })
  // 打开开发工具
  // mainWindow.webContents.openDevTools();
}

// 设置窗口名称
const handleSetTitle = (event, title) => {
  const webContents = event.sender
  const win = BrowserWindow.fromWebContents(webContents)
  win.setTitle(title)
}
app.whenReady().then(() => {
  //
  ipcMain.on('set-title', handleSetTitle)
  createWindow();
})

app.on('window-all-closed', () => {
  console.log('window-all-closed');
  app.quit()
})